'''
Created on 21.05.2013

@author: User
'''
from nose.plugins.xunit import Xunit
from ConfigParser import SafeConfigParser
import re
from xml.etree.ElementTree import fromstring
from xml.etree.ElementTree import tostring


class patchedXunit(Xunit):
    
    def __init__(self,configFile):
        super(patchedXunit, self).__init__()
        self.configFile = configFile
        parser = SafeConfigParser()
        parser.read(configFile)
        self.browser = parser.get('rc_configuration','browser')
        self.platform = parser.get('rc_configuration','platform')
    
    def setConfigurationDetails(self):
        root = fromstring(self.errorlist[-1])      
        old_class = root.get("classname")
        root.set("classname","%s_%s_%s"%(self.browser,self.platform,old_class))
        self.errorlist[-1]=tostring(root)
               
    def addError(self, test, err, capt=None):
        Xunit.addError(self, test, err, capt=capt)
        self.setConfigurationDetails()

    
    def addFailure(self, test, err, capt=None, tb_info=None):
        Xunit.addFailure(self, test, err, capt=capt, tb_info=tb_info)
        self.setConfigurationDetails()


    def addSuccess(self, test, capt=None):
        Xunit.addSuccess(self, test, capt=capt)
        self.setConfigurationDetails()
